package com.atguigu.tingshu.album.rpc;

import com.atguigu.tingshu.album.mapper.AlbumStatMapper;
import com.atguigu.tingshu.album.service.AlbumInfoService;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.album.service.TrackInfoService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.*;
import com.atguigu.tingshu.vo.album.AlbumStatVo;
import com.atguigu.tingshu.vo.album.TrackListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @BelongsProject: tingshu-backend
 * @BelongsPackage: com.atguigu.tingshu.album.rpc
 * @Author: coilk
 * @CreateTime: 2025-03-17  16:56
 * @Description:
 * @Version: 1.0
 */
@RestController
@RequestMapping("/rpc/inner/albuminfo")
public class AlbumInfoRpcController {

    @Autowired
    private AlbumInfoService albumInfoService;

    @Autowired
    private BaseCategoryService baseCategoryService;

    @Autowired
    private TrackInfoService trackInfoService;

    @GetMapping("/getAlbumInfoAndAttrValue/{albumId}")
    Result<AlbumInfo> getAlbumInfoAndAttrValue(@PathVariable(value = "albumId") Long albumId) {

        AlbumInfo albumInfo = albumInfoService.getAlbumInfo(albumId);
        return Result.ok(albumInfo);
    }

    @GetMapping("/getAlbumCategory/{albumId}")
    Result<BaseCategoryView> getAlbumCategory(@PathVariable(value = "albumId") Long albumId) {

        BaseCategoryView baseCategoryView = baseCategoryService.getAlbumCategory(albumId);
        return Result.ok(baseCategoryView);

    }

    @GetMapping("/getAlbumStat/{albumId}")
    Result<AlbumStatVo> getAlbumStat(@PathVariable(value = "albumId") Long albumId) {

        AlbumStatVo albumStatVo = albumInfoService.getAlbumStat(albumId);
        return Result.ok(albumStatVo);
    }

    @GetMapping("/getBaseCategory3ListByC1Id/{albumId}")
    Result<List<BaseCategory3>> getBaseCategory3ListByC1Id(@PathVariable(value = "albumId") Long c1Id){
        List<BaseCategory3> topBaseCategory3 = baseCategoryService.findTopBaseCategory3(c1Id);
        return Result.ok(topBaseCategory3);
    }

    @GetMapping("/getAllCategory1Id")
    Result<List<Long>> getAllCategory1Id() {

        List<Long> c1Ids = baseCategoryService.getAllCategory1Id();
        return Result.ok(c1Ids);
    }

    @PostMapping("/getTrackListByIds")
    Result<List<TrackListVo>> getTrackListByIds(@RequestBody List<Long> trackIdList) {
        List<TrackListVo> trackListVoList = trackInfoService.getTrackListByIds(trackIdList);
        return Result.ok(trackListVoList);
    }

    @GetMapping("/getAlbumInfoIdList")
    Result<List<Long>> getAlbumInfoIdList() {
        List<Long> albumIdList = albumInfoService.getAlbumInfoIdList();
        return Result.ok(albumIdList);
    }

    @GetMapping("/getTrackListByCurrentTrackId/{userId}/{trackId}/{trackCount}")
    Result<List<TrackInfo>> getTrackListByCurrentTrackId(@PathVariable(value = "userId") Long userId,
                                                         @PathVariable(value = "trackId") Long trackId,
                                                         @PathVariable(value = "trackCount") Integer trackCount) {
        List<TrackInfo> trackInfoList = trackInfoService.getTrackListByCurrentTrackId(userId, trackId, trackCount);
        return Result.ok(trackInfoList);
    }

    @GetMapping("/getTrackInfoByTrackId/{trackId}")
    Result<TrackInfo> getTrackInfoByTrackId(@PathVariable(value = "trackId") Long trackId) {
        TrackInfo trackInfo = trackInfoService.getById(trackId);
        return Result.ok(trackInfo);
    }
}
